﻿Public Class AuctionItemReader

    Public Shared Function GET_AuctionItem(ByVal TableRopeItemsIndividual As LuaInterface.LuaTable, ByVal sServerName As String, ByVal sFactionName As String) As AuctionItem
        Dim oItem As AuctionItem = Nothing
        Try
            If Not IsNothing(TableRopeItemsIndividual) Then
                oItem = New AuctionItem
                oItem.RAW_LINK = CStr(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(0))).Trim
                oItem.ITEM_LEVEL = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(1)))
                oItem.ITEM_TYPE = CStr(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(2))).Trim
                oItem.ITEM_SUBTYPE = CStr(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(3))).Trim
                oItem.IEQUIP = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(4)))
                oItem.STACK_PRICE = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(5)))
                oItem.TIME_LEFT = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(6)))
                oItem.SCAN_TIME = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(7)))
                oItem.ITEM_NAME = CStr(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(8)))
                oItem.TEXTURE_STRING = CStr(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(9))).Trim
                oItem.ITEM_COUNT = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(10)))
                oItem.ITEM_QUALITY = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(11)))
                oItem.ITEM_MINBID = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(14)))
                oItem.ITEM_MININC = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(15)))
                oItem.ITEM_BUYOUT = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(16)))
                oItem.ITEM_CURBID = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(17)))
                oItem.ITEM_SELLER = CStr(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(19))).Trim
                oItem.ServerName = sServerName
                oItem.FactionName = sFactionName
                oItem.SCAN_DATE = GET_SCAN_DATE(oItem.SCAN_TIME)
                oItem.ITEM_ID = CInt(TableRopeItemsIndividual.Item(TableRopeItemsIndividual.Keys(22)))
                Return oItem
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Shared Function GET_SCAN_DATE(ByVal scDate As Integer) As Date
        Dim DTRaw As DateTime = New System.DateTime(1970, 1, 1, 0, 0, 0, 0)
        Dim DTOut As DateTime = Nothing
        '// Add the number of seconds in UNIX timestamp to be converted.
        DTOut = DTRaw.AddSeconds(scDate)
        Return New Date(DTOut.Year, DTOut.Month, DTOut.Day)
    End Function

End Class
